#include<iostream>
#include<vector>
using namespace std;

int ne[4][2] = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
void dfs(vector<vector<char>>& v, int r, int c)
{
	v[r][c] = 'F';

	for (int i = 0; i<4; i++)
	{
		int newr = r + ne[i][0];
		int newc = c + ne[i][1];

		if (newr<0 || newc<0 || newr >= v.size() || newc >= v[0].size())
			continue;

		if (v[newr][newc] == 'O')
			dfs(v, newr, newc);
	}


}
void solve(vector<vector<char>>& board) {
	if (board.empty())
		return;
	int c = board[0].size();
	int r = board.size();

	for (int i = 0; i<c; i++)
	{
		if (board[0][i] == 'O')
			dfs(board, 0, i);
		if (board[r - 1][i] == 'O')
			dfs(board, r - 1, i);
	}

	for (int i = 0; i<r; i++)
	{
		if (board[i][0] == 'O')
			dfs(board, i, 0);
		if (board[i][c - 1] == 'O')
			dfs(board, i, c - 1);
	}

	for (int i = 0; i<r; i++)
	for (int j = 0; j<c; j++)
	{
		if (board[i][j] == 'F')
			board[i][j] = 'O';
		else
			board[i][j] = 'X';
	}

}

int main()
{
	vector<vector<char>> v = { { 'X', 'X', 'X', 'X' }, { 'X', 'O', 'O', 'X' }, { 'X', 'X', 'O', 'X' }, { 'X', 'O', 'X', 'X' } };
	solve(v);
}